package WorkTask3;


import java.io.Serializable;

public class Student implements Serializable {
    private static final long serialVersionUID = 1514534970227877232L;
    private String name;
    private int id;
    private int age;

    public Student() {
    }

    public Student(String name, int id, int age) throws AgeException, IdException {
        setId(id);
        setName(name);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) throws IdException {
        if (id >= 0 ){
            this.id = id;
        }else {
            throw new IdException("学号数据不合理！");
        }
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "姓名='" + name + '\'' +
                ", id=" + id +
                ", 年龄=" + age +
                '}';
    }

    public void setAge(int age) throws AgeException {
        if (age > 0 && age < 100){
            this.age = age;
        }else {
            throw new AgeException("年龄数据不合理！");
        }
    }

}
class AgeException extends Exception{
    private static final long serialVersionUID = 8860786743247186614L;

    public AgeException(String message) {
        super(message);
    }

    public AgeException() {

    }
}

class IdException extends Exception{
    private static final long serialVersionUID = -2481621932207610787L;

    public IdException(String message) {
        super(message);
    }

    public IdException() {
    }
}
